package com.hqyj.cl.mapper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.cl.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * @description：
 * @author：cc
 * @date：2021/10/12 10:23
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/spring-mybatis.xml"})
public class TestSQL {
    @Autowired
    private UserMapper userMapper;

    // selectAllByUsername
    @Test
    public void selectAllByUsername(){
        System.out.println(userMapper.selectAllByUsername("a"));
    }

    // login
    @Test
    public void login(){
        System.out.println(userMapper.login(new User("admin","111")));
    }

    // selectAllUser
    @Test
    public void selectAllUser(){
        //使用PageHelper实现分页
        //开启分页
        PageHelper.startPage(1,1);
        //查询数据库，获取查询数据
        List<User> userList=userMapper.selectAllUser();
        // 封装查询的数据在pageInfo对象中
        PageInfo<User> userPageInfo=new PageInfo<>(userList);
        // 输出pageInfo对象
        System.out.println(userPageInfo);
    }

}
